#include <bits/stdc++.h>
using namespace std;
#include <bits/stdc++.h>
using namespace std;
class Solution
{
public:
    vector<int> findAnagrams(string s, string p)
    {
        int n = s.size(), m = p.size();
        int count = 0;
        int l = 0, r = 0;
        int hash[27] = {0}, hash2[27] = {0};
        vector<int> ans;
        for (auto &i : p)
        {
            hash2[i - 'a']++;
        }
        for (; r < n; r++)
        {
            hash[s[r] - 'a']++;
            if (hash[s[r] - 'a'] <= hash2[s[r] - 'a'])
                count++;
            if (r - l + 1 > m)
            {
                if (hash[s[l] - 'a'] <= hash2[s[l] - 'a'])
                {
                    count--;
                }
                hash[s[l] - 'a']--;
                l++;
            }
            if (count == m)
            {
                ans.push_back(l);
            }
        }
        return ans;
    }
};